﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UtilityExtensions;
using System.Data.SqlClient;
using BOL;
using DAL;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.ReportSource;
using Website.Logger;


namespace UILGestion.Rpt
{
    public partial class KardexItemRpt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                try
                {
                    idObra.Value = (string)Request.QueryString["idObra"];
                    idAlmacen.Value = (string)Request.QueryString["idAlmacen"];

                    menuObraCtrl1.loadMenuAlmacen(int.Parse(idObra.Value), int.Parse(idAlmacen.Value));
                    formatForm();
                }


                catch (SqlException sqlex)
                {
                    WebServerSideSqlError.Log(sqlex);
                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                     "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


                }
                catch (Exception ex)
                {
                    WebServerSideError.Log(ex);
                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                     "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

                }

            }
        }



        private void formatForm()
        {

            finTextBox.Text=DateTime.Now.ToShortDateString();
            inicioTextBox.Text = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToShortDateString();
            

            

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ///LoadReport();

        }

        //private void LoadReport()
        //{

        //    //(DD/MM/yyyy)
        //    System.IFormatProvider MiFp =
        //        new System.Globalization.CultureInfo("es-ES", false);


        //    KardexBL KARBOL = new KardexBL();
        //    DateTime fechainicio = DateTime.ParseExact(inicioTextBox.Text, "dd/MM/yyyy", MiFp);
        //    DateTime fechaFin = DateTime.ParseExact(finTextBox.Text, "dd/MM/yyyy", MiFp);


        //    ReportDocument crystalReport = new ReportDocument();

        //    crystalReport.Load(Server.MapPath("KardexValViewRPT.rpt"));
        //    crystalReport.SetDataSource(
        //         KARBOL.loadKardexValRPT(fechainicio, fechaFin, int.Parse(almacenDropDownList.SelectedValue))
        //        );
        //    impresionDocumento.ReportSource = crystalReport;
        //}

        protected void inicioTextBox_TextChanged(object sender, EventArgs e)
        {
            //  verificamos que el  valor no debe al ultimo cierre
        }
        


        protected void CrystalReportViewer1_ReportRefresh(object source, ViewerEventArgs e)
        {
           // LoadReport();
        }

        protected void CrystalReportViewer1_Load(object sender, EventArgs e)
        {
           // LoadReport();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}